package com.alex.core.util;

import com.alex.core.entity.ApiResponse;
import com.alex.core.enums.ApiResponseEnum;

/**
 * @author cb
 * @date 2019/11/13 13:27
 */
public class ApiResponseUtil {

    private ApiResponseUtil() {
    }

    public static ApiResponse success(Object data) {
        return ApiResponse.builder().flag(true).code(ApiResponseEnum.SUCCESS.getCode()).errMsg(ApiResponseEnum.SUCCESS.getErrMsg()).data(data).build();
    }

    public static ApiResponse failure(ApiResponseEnum apiResponseEnum) {
        return ApiResponse.builder().flag(false).code(apiResponseEnum.getCode()).errMsg(apiResponseEnum.getErrMsg()).build();
    }

    public static ApiResponse failure(String code, String errMsg) {
        return ApiResponse.builder().flag(false).code(code).errMsg(errMsg).build();
    }
}
